package com.chhuang.ewcrm.string;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

import org.apache.commons.lang3.StringUtils;

/**
 * 
 * @ClassName: UrlCodeUtil
 * @Description: url地址编码与解析
 * @author: 黄晨
 * @date: 2015-3-25
 *
 */
public class UrlCodeUtil {
	private UrlCodeUtil(){}

	/**
	 * url编码
	 * @param arg0
	 * @param charset
	 * @return
	 */
	public static String UrlEncode(String arg0,String charset){
		if(StringUtils.isNotEmpty(arg0)){
			try {
				return URLEncoder.encode(arg0, charset);
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}
		return arg0;
	}

	/**
	 * url解码
	 * @param arg0
	 * @param charset
	 * @return
	 */
	public static String UrlDecode(String arg0,String charset){
		if(StringUtils.isNotEmpty(arg0)){
			try {
				return URLDecoder.decode(arg0, charset);
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}
		return arg0;
	}
}
